home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / QuickTime VR / MacOS / QuickDraw™ 3D 1.0.6F4 SDK / Samples / SampleCode / CustomAttribute / NetscapeLink.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-20  |  4.5 KB  |  206 lines  |  [TEXT/CWIE]

  1. #include <EPPC.h>
  2. #include <AppleEvents.h>
  3. #include <Aliases.h>
  4. #include <string.h>
  5. #include <Memory.h>
  6. #include <TextUtils.h>
  7. #include <Strings.h>
  8.  
  9. #include "IsAppRunning.h"
  10.  
  11. void testNetscape(void);
  12.  
  13. static AEDesc theAddressDesc;
  14.  
  15. static Boolean Find_NetScape(void);
  16.  
  17. static pascal Boolean MyFilter(LocationNamePtr locationName, PortInfoPtr thePortInfo);
  18. static pascal Boolean MyIdle(EventRecord *theEvent, long *sleepTIme, RgnHandle *mouseRgn);
  19. static Boolean OpenNetscape(void);
  20. static OSErr CloseNetscape(void);
  21. static void ActivateNetScape(void);
  22.  
  23. static Boolean opened = false;
  24.  
  25. /**************************************************************************************************
  26. *
  27. *
  28. *                        PUBLIC FUNCTIONS
  29. *
  30. *
  31. **************************************************************************************************/
  32.  
  33. Boolean OpenURL(char *url);    // go to the page specified by the url
  34.  
  35. void ShowFile(char *name);    // have netscape show the file with the name (may launch helper apps)
  36.  
  37.  
  38. Boolean OpenURL(char *name)
  39. {
  40.     AppleEvent    theAppleEvent, theReply;
  41.     OSErr        err;
  42.  
  43.     if (Find_NetScape() == false)
  44.         return false;
  45.         
  46.                 
  47.     err = AECreateAppleEvent ('WWW!','OURL', &theAddressDesc,
  48.                              kAutoGenerateReturnID, kAnyTransactionID, &theAppleEvent);
  49.                                 
  50.         
  51.     err = AEPutParamPtr(&theAppleEvent, keyDirectObject, typeChar, name, strlen(name));
  52.         
  53.     err = AESend(&theAppleEvent, &theReply, 
  54.                 kAEWaitReply,kAENormalPriority, kNoTimeOut,
  55.                 NewAEIdleProc(MyIdle), NewAEFilterProc(MyFilter));
  56.     
  57.     if( err == noErr )
  58.         return true;
  59.     else
  60.         return false;            
  61. }
  62.  
  63. void ShowFile(char *name)
  64. {
  65.     AppleEvent    theAppleEvent, theReply;
  66.     OSErr        err;
  67.     AliasHandle alias = nil;
  68.     FSSpec fss;
  69.     short vRefNum;
  70.     char pstr[256];
  71.     
  72.         
  73.     if (Find_NetScape() == false)
  74.         return;
  75.         
  76.                 
  77.     err = AECreateAppleEvent ('WWW!','SHWL', &theAddressDesc,
  78.                              kAutoGenerateReturnID, kAnyTransactionID, &theAppleEvent);
  79.                                 
  80.     
  81.     GetVol(nil, &vRefNum);
  82.     strcpy(pstr, name);
  83.     c2pstr(pstr);
  84.     
  85.     err = FSMakeFSSpec( vRefNum, 0, (StringPtr)pstr, &fss);
  86.     err = NewAlias(nil, &fss, &alias);
  87.             
  88.     err = AEPutParamPtr(&theAppleEvent, keyDirectObject, typeAlias, &alias, 
  89.                             GetHandleSize((Handle)alias));
  90.     
  91.     err = AESend(&theAppleEvent, &theReply, 
  92.                 kAEWaitReply,kAENormalPriority, kNoTimeOut,
  93.                 NewAEIdleProc(MyIdle), NewAEFilterProc(MyFilter));
  94. }
  95.  
  96. /**************************************************************************************************
  97. *
  98. *
  99. *                        PUBLIC FUNCTIONS
  100. *
  101. *
  102. **************************************************************************************************/
  103.  
  104. static pascal Boolean MyFilter(LocationNamePtr locationName, PortInfoPtr thePortInfo)
  105. {
  106. #pragma unused (locationName, thePortInfo)
  107.     return true;
  108. }
  109.  
  110. static pascal Boolean MyIdle(EventRecord *theEvent, long *sleepTIme, RgnHandle *mouseRgn)
  111. {
  112. #pragma unused (theEvent, sleepTIme, mouseRgn)
  113.     return false;
  114. }
  115.  
  116.  
  117. static Boolean Find_NetScape(void)
  118. {
  119.     ProcessSerialNumber targetPSN ;
  120.     
  121.     ProcessInfoRec     targetPIRec ;
  122.     Str255                 targetName ;
  123.     OSErr                     err = paramErr;
  124.     Boolean                retVal = false ;
  125.     
  126.     // if we are running we want the PSN and stuff,
  127.     // otherwise we need to launch it and get the information
  128.     
  129.     if(!IsAppRunning( 'APPL',
  130.                       'MOSS',
  131.                       &targetPSN, 
  132.                       &targetPIRec, 
  133.                       targetName ) )
  134.     {
  135.             err = LaunchApp( 'MOSS' ) ;
  136.  
  137.             if( err == noErr)
  138.                     retVal = true;
  139.                 else
  140.                     retVal = false;
  141.     } else if (targetPIRec.processSignature == 'MOSS')
  142.         retVal = true;
  143.     else 
  144.         retVal = false ;
  145.  
  146.     if( retVal == true ) {
  147.         if( opened == false) {    // you only want to create the descriptor once
  148.             DescType sig = 'MOSS';
  149.             
  150.             err = AECreateDesc (typeApplSignature, (Ptr) &sig, sizeof(DescType), &theAddressDesc);
  151.             if (err != noErr) {
  152.                 retVal = false;
  153.             } else {
  154.                 opened = true;
  155.                 retVal = true;
  156.             }
  157.         }
  158.     } else
  159.         retVal = false;
  160.     
  161.     return retVal ;
  162.  
  163. }
  164.  
  165. static Boolean OpenNetscape(void) 
  166. {
  167.     OSErr err = noErr;
  168.  
  169.     
  170.     if (!opened) {
  171.         if (Find_NetScape() == false)
  172.             return false;
  173.         
  174.         {
  175.             DescType sig = 'MOSS';
  176.     
  177.             err = AECreateDesc (typeApplSignature, (Ptr) &sig, sizeof(DescType), &theAddressDesc);
  178.             if (err == noErr)
  179.                 opened = true;
  180.             else
  181.                 return false;
  182.         }
  183.     }
  184.     
  185.     return true;
  186. }
  187.  
  188. static OSErr CloseNetscape(void)
  189. {
  190.     return AEDisposeDesc (&theAddressDesc);
  191. }
  192.     
  193. static void ActivateNetScape(void)
  194. {
  195.     AppleEvent    theAppleEvent, theReply;
  196.     OSErr        err;
  197.  
  198.     if (Find_NetScape() == false)
  199.         return;
  200.  
  201.     err = AECreateAppleEvent('WWW!','ACTV',&theAddressDesc,
  202.                 kAutoGenerateReturnID, kAnyTransactionID,&theAppleEvent);
  203.     
  204.     err = AESend(&theAppleEvent, &theReply, kAEWaitReply,kAENormalPriority, kNoTimeOut, nil, nil);
  205.  
  206. }